<%@ page pageEncoding="UTF-8"%>
<script type="text/x-template" id="edit_tag">
	<div class="_edit_tag">
        <div class="_pop-container">
            <div class="_top">
                修改扩展标签
            </div>
            <div class="_content">
                <div class="_each-content">
                    <span class="_title">名称: </span>
                    <input class="_input" type="text" v-model="editName">
                </div>
                <div class="_each-content">
                    <span class="_title">备注: </span>
                    <textarea class="_input" type="text" v-model="editRemark"></textarea>
                </div>
                <div class="_each-content">
                    <span class="_title"></span>
                    <div class="_submit-container">
                        <div class="_submit" @click="submit()">确定</div>
                    </div>
                </div>
            </div>
            <img class="_close" src="/images/components/add_member/ic-close.png" alt="" @click="closeAddMember()">
        </div>
	</div>
</script>
<link rel="stylesheet" href="/css/components/edit_tag.css"/>
<script>
	var editTag = {
		template: "#edit_tag",
        props: ["name", "remark", "id"],
		data: function() {
			return {
                editName: "",
                editRemark: "",
                originName: "",
			}
		},
        methods: {
            closeAddMember: function() {
                this.$dispatch("closeEditTagShow");
            },
            submit: function() {
                var _this = this;
                var editName = this.editName.trim();
                var editRemark = this.editRemark.trim();
                if (editName.length == 0) {
                    this.$dispatch("danger", "请输入标签名称");
                    return;
                }
                if (!/^.{2,10}$/.test(editName)) {
                    this.$dispatch("danger", "标签名为2-10位");
                    return;
                }
                if (editRemark.length > 50) {
                    this.$dispatch("danger", "备注不得超过50个字");
                    return;
                }
                this.$dispatch("deleteSuccess", {
                    top: "编辑标签",
                    title: "即将修改这个标签",
                    content: "修改标签",
                    arg: function() {
                        $.ajax({
                            type: 'POST',
                            url: "tag_manage.jsp",
                            data: {
                                act: "tagEdit",
                                hospital: HOSPITAL,
                                tag_id: _this.id,
                                tag_name: editName,
                                tag_alias: editRemark,
                            },
                            success: function(res) {
                                res = JSON.parse(res);
                                if (res.errcode == 0) {
                                    _this.$dispatch("message", "标签修改成功")
                                    _this.$dispatch("editTagSuccess");
                                } else {
                                    _this.$dispatch("danger", res.errmsg);
                                }
                            },
                        });
                    }
                });
            }
        },
		ready: function() {
            this.editName = this.name;
            this.editRemark = this.remark;
            this.originName = this.name;
		},
        components: {

        }
	}
</script>
